<template>
  <div class="search">
    <el-autocomplete
        class="form"
        clearable
        placeholder="请输入医院名称"
        v-model="hosname"
        :fetch-suggestions="querySearch"
        :trigger-on-focus="false"
        @select = "getDetail"
    />
    <el-button :icon="Search" size="default" type="primary">搜索</el-button>
  </div>
</template>

<script lang="ts" setup>
import {ref} from "vue";
//引入element-plus提供的图标
import {Search} from '@element-plus/icons-vue'
import {reqHospitalInfo} from "@/api/home"
import {useRouter} from "vue-router";

let $router = useRouter();
const hosname = ref<String>("");

const querySearch = (name: string, cb: any) => {
  reqHospitalInfo(name).then((result) => {
    let showdata = result.data.map(item => {
      return {
        value: item.hosname
      }
    })
    cb(showdata)
  })
}

const getDetail = (item:any)=>{
  $router.push({path:'/hospital'})
}



//深度选择器:>>> /deep/ ::v-deep
</script>

<script lang="ts">
export default {
  name: "Search",
}
</script>

<style lang="scss" scoped>
.search {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px 0;

  ::v-deep(.el-input__wrapper) {
    width: 600px;
    margin-right: 10px;
  }
}
</style>
